import importlib
import os


def load_routers(app):
    routers_path = os.path.dirname(os.path.abspath(__file__))
    for file in os.listdir(routers_path):
        if file.endswith('_controller.py'):
            module_name = file[:-3]  # 去掉 .py 后缀
            module_path = f"controllers.{module_name}"
            module = importlib.import_module(module_path)
            if hasattr(module, 'router'):
                app.include_router(module.router)
